﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace WMS.API.Controllers
{
    /// <summary>
    /// 上传图片控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UplodController : ControllerBase
    {
        [HttpPost]
        public IActionResult UplodFile() {

            try
            {
                string filePath = "";

                var files = Request.Form.Files;

                foreach (var file in files)
                {
                    filePath = Directory.GetCurrentDirectory()+ "/wwwroot/img/ProductManage/" + file.FileName;
                    using (var stream = new FileStream(filePath, FileMode.Create))
                    {
                        file.CopyTo(stream);
                    }

                    filePath= "http://localhost:5233/img/ProductManage/" +  file.FileName;
                }
                return Ok(filePath);              
            }
            catch (Exception)
            {
                throw;
            }
            
        }
    }
}
